package mn.idax.exchange.otc.service;

import mn.idax.exchange.otc.domain.*;
import mn.idax.exchange.otc.domain.capital.CapitalAPIParamsDTO;
import mn.idax.exchange.otc.domain.capital.ChangeListData;
import mn.idax.exchange.otc.entity.Account;
import mn.idax.exchange.otc.entity.OTCAds;
import mn.idax.exchange.otc.entity.OTCOrder;
import mn.idax.exchange.otc.enums.AccountTransactionEnum;
import mn.idax.exchange.otc.vo.*;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Create by jack_huang on 2018/8/6
 */
public interface OTCOrderService {

    OTCOrder getOrderByOrderNum(String orderNum);

    OrderShowResultDTO getOrderPage(OrderPageDTO orderPageDTO);


    //订单状态变更时发送通知 功能而非接口
//    Boolean updateOrderStateAndSendMessage(OrderChangeDTO orderChangeDTO,Integer userId);

    Boolean updateOrderStateCommon(OTCOrder order,OrderChangeDTO orderChangeDTO, Integer userId);

    /**
     * 功能描述:
     * 优化updateOrderStateCommon逻辑
     *
     * @param:
     * @return:
     * @auther: dison
     * @date: 2018/9/7 10:16
     */
    Boolean updateOrderStateCommon(OTCOrder order, OTCOrder oldOrder, Integer userId);

    Map<String, Object> getOrderDetails(String orderNum, Integer userId, Integer usersource);

    OTCOrder createOrder(CreateOrderDTO createOrderDTO,OTCAds otcAds);

    CreateOrderResponse sendCreateOrderMessage(OTCOrder order);

    OTCOrder placeOrder(CreateOrderDTO createOrderDTO, OTCAds otcAds, OTCOrder order, BigDecimal coinFeeRate);

    List<OTCOrder> getOrderPayTimeout(Date date);

    /**
     * 功能描述:
     * 通过订单号和用户ID获取订单信息
     *
     * @param:
     * @return:
     * @auther: dison
     * @date: 2018/8/16 16:40
     */
    OTCOrder getOrderByOrderNumAndUserId(String orderNum, Integer userId);


    /**
     * 功能描述:
     * 币种放行
     *
     * @param:
     * @return:
     * @auther: dison
     * @date: 2018/8/16 19:02
     */
    CapitalAPIParamsDTO releaseConin(OTCOrder otcOrder,Integer userId);

    boolean releasePostProcess(OTCOrder otcOrder);

    void sendMessageAtRelease(OTCOrder oldOrder);


    //标记付款已完成
    Boolean confirmPaid(String orderNum, Integer payMethod, Integer userId);


    //取消订单
    CapitalAPIParamsDTO cancelOrder(OTCOrder otcOrder, Integer userId);

    //发送消息
    void pushOrderStateMessage(OTCOrder order, Integer orderState,Integer userId);

    OTCOrder getOTCOrderByUniqueKey(String uniqueKey);

    /**
     * 功能描述:
     * 获取当日下单数量
     *
     * @param:
     * @return:
     * @auther: dison
     * @date: 2018/8/27 16:49
     */
    Long getPlaceOrderQty();

    /**
     * 功能描述:
     * 获取当日取消次数
     *
     * @param:
     * @return:
     * @auther: dison
     * @date: 2018/8/27 19:25
     */
    Long getCancelOrderNum(Integer loginUserId);

    /**
     * 功能描述:
     * 添加当日取消次数
     *
     * @param:
     * @return:
     * @auther: dison
     * @date: 2018/8/27 19:33
     */
    Long addCancelOrderNum(Integer loginUserId);

    /**
     * 功能描述:
     * 查询订单导出的数据
     *
     * @param:
     * @return:
     * @auther: dison
     * @date: 2018/8/29 17:52
     */
    List<OrderExcelDTO> queryExportData(OrderPageDTO orderPageDTO);

    //买卖方未支付的订单笔数
    Integer getNumbereOfUnpaid(Integer buyer, Integer seller);

    OTCOrder selectByPrimaryKey(Integer orderId);

    /**
     * 功能描述:
     * 分页查询累计交易记录
     *
     * @param:
     * @return:
     * @auther: dison
     * @date: 2018/10/16 14:02
     */
    PageVo<TradeRecordVO> listTradeRecord(TradeRecordDTO tradeRecord);

    /**
     * 取消订单参数校验
     * @param otcOrder
     * @param userId
     * @return
     */
    CapitalAPIParamsDTO checkCancelOrderServiceParams(OTCOrder otcOrder, Integer userId);

    /**
     * 超时未支付订单参数校验
     * @param otcOrder
     * @param userId
     * @return
     */
    CapitalAPIParamsDTO checkForzenOrderServiceParams(OTCOrder otcOrder, Integer userId) throws Exception;

    /**
     * 放行订单参数校验
     * @param otcOrder
     * @param userId
     * @return
     */
    CapitalAPIParamsDTO checkReleaseOrderServiceParams(OTCOrder otcOrder, Integer userId);
    /**
     *
     * @param account
     * @param otcOrder
     * @param accountTransactionEnum
     * @return
     */
    ChangeListData makeChangeListData(Account account, OTCOrder otcOrder, AccountTransactionEnum accountTransactionEnum);

    /**
     * 获取app 2.3上线后交易完成 但没评价的订单
     * @return
     */
    List<NeedAutoCommentDTO> getNeedAutoCommentOrder();

    /**
     * 取消超过三次冻结用户
     * @param userId
     */
    void cancelOrderNumMoreThanThree(Integer userId);


    /**
     * 获取用户的成交信息
     * @param allUpAdPublisherId
     * @return
     */
    List<UserTradeInfo> getUserTwoMonthsAgoTradeInfo(List<Integer> allUpAdPublisherId);

    /**
     * 计算广告排序权重
     * @param userTradeInfos
     */
    void calculationUserProportion(List<UserTradeInfo> userTradeInfos,List<Integer> allUpAdPublisherId);
}
